/**
 * @Title: FileTableServiceImpl.java
 * @Copyright (C) 2017 龙图软件
 * @Description:
 * @Revision History:
 * @Revision 1.0 2017-12-4  yuanchunci
 */
 

package com.ycc.fileTransfer.service.impl;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ycc.fileTransfer.entity.FileTable;
import com.ycc.fileTransfer.mapper.FileTableMapper;
import com.ycc.fileTransfer.service.FileTableService;

/**
 * @ClassName: FileTableServiceImpl
 * @Description: Description of this class
 * @author <a href="mailto:XXX@qq.com">yuanchunci</a>于 2017-12-4 下午2:10:30
 */
@Service
public class FileTableServiceImpl implements FileTableService {
@Resource
FileTableMapper filetableMapper;

/**.
 * <p>Title: insertOne</p>
 * <p>Description: </p>
 * @param p
 * @throws Exception
 * @see com.ycc.fileTransfer.service.FileTableService#insertOne(java.util.Map)
 */
@Override
public void insertOne(Map p) throws Exception {
	// TODO Auto-generated method stub
	filetableMapper.insertOne(p);
}

/**.
 * <p>Title: get</p>
 * <p>Description: </p>
 * @param p
 * @return
 * @throws Exception
 * @see com.ycc.fileTransfer.service.FileTableService#get(java.util.Map)
 */
@Override
public List get(Map p) throws Exception {
	// TODO Auto-generated method stub
	return filetableMapper.get(p);
}

/**.
 * <p>Title: delete</p>
 * <p>Description: </p>
 * @param s
 * @return
 * @throws Exception
 * @see com.ycc.fileTransfer.service.FileTableService#delete(java.lang.String)
 */
@Override
public int delete(String s) throws Exception {
	// TODO Auto-generated method stub
	Map p=new HashMap();
	p.put("id", s);
	List<FileTable> ls=filetableMapper.get(p);
	if(ls.size()>0){
		String path=ls.get(0).getFilepath()+"\\"+ls.get(0).getID()+ls.get(0).getFilename();
		String thumpath=ls.get(0).getFilepath()+"\\thum\\thum_"+ls.get(0).getID()+ls.get(0).getFilename();
		File f=new File(path);
		if(f.exists()){
			f.delete();
		}
		File thumf=new File(thumpath);
		if(thumf.exists()){
			thumf.delete();
		}
	}
	 //filetableMapper.delete(s)
	return filetableMapper.delete(s);
}
}
